#include <stdio.h>
#include <string.h>
#include <unistd.h>

#define NUM 128
#define SZ  64
int main()
{
    char command[NUM] = {0};
    for(;;)
    {
	 printf("[LOJ@iZ0jldbnf3pztqrego9h2lZ lesson2]# ");
	 fflush(stdout);
         command[0] = 0; //清空缓冲区
         fgets(command, NUM, stdin);
         command[strlen(command)-1] = 0; //去掉回车键
         //切分字符串
	 char* argv[SZ];
         const char* sep = " ";
         argv[0] = strtok(command, sep);
         int i = 1;
	 while(argv[i] = strtok(NULL, sep))
         {
	     ++i;
	 }
         //for(int i = 0;argv[i];++i)
	 //{
	 //    printf("%s\n", argv[i]);
	 //}
         if(fork() == 0)
         {
 	     execvp(argv[0], argv);
	     exit(0);
	 }
 	 if(strcmp(argv[0], "cd") == 0)
	 {
	     if(argv[1])
	     	chdir(argv[1]);
	 }
         waitpid(-1, NULL, 0);
    }
    return 0;
}
